var MHLandscaping = function()
{
	var galleryInitial = false;
	var beforeAfterInitial = false;
	
	function init()
	{
		$(document.body).removeClass('no-js').addClass('js');
		
		pngFix();
		attachServiceImageFunctionality();
	}
	
	function pngFix() {
		if (typeof(jQuery.fn.pngFix) == 'function') {
			$(document).pngFix();
		}	
	}
	
	function attachServiceImageFunctionality()
	{
		if ($('.before-after').length == 0) 
		{
			showGallery();
			
			return;
		} else {
			resetServiceImageFunctionality();
			
			switchServiceImageFunctionality(window.location.hash);
			
			$('.services-image-btn').click(function(){
				resetServiceImageFunctionality();
				switchServiceImageFunctionality($(this).find('a').attr('href'));
			});
		}
		
	}
	
	function resetServiceImageFunctionality()
	{
		hideGallery();
		hideBeforeAfter();
		hideServiceImageButtons();
	}
	
	function switchServiceImageFunctionality(id)
	{
		switch(id)
		{
			case '#before-after':
				showBeforeAfter();
				$('#gallery-btn').show();
				break;
			
			default:
				showGallery();
				$('#before-after-btn').show();
				break
		}
	}
	
	function showGallery()
	{
		if ($('.flexslider').length > 0) 
		{
			$('.flexslider').show();
			
			if(galleryInitial == false)
			{
				$('.flexslider').flexslider({
			          animation: "slide",
			          directionNav: false, 
			          controlsContainer: ".pagination"
			    });
				
				galleryInitial = true
			}
			
		}
	}
	
	function showBeforeAfter()
	{
		if ($('.before-after').length > 0) 
		{
			$('.before-after').show();
			
			if(beforeAfterInitial == false)
			{
				$('.before-after').beforeAfter({
					dividerColor: '#fff',
					animateIntro : true,
			        introDelay : 1000,
			        introDuration : 500,
			        imagePath:'/static/img/before_after/',
			        showFullLinks : false
				});
				beforeAfterInitial = true;
			}
			
		}
	}
	
	function hideGallery()
	{
		if ($('.flexslider').length > 0) 
		{
			$('.flexslider').hide();
		}
	}
	
	function hideBeforeAfter()
	{
		if ($('.before-after').length > 0) 
		{
			$('.before-after').hide();
		}
	}
	
	function hideServiceImageButtons()
	{
		if ($('.services-image-btn').length > 0) 
		{
			$('.services-image-btn').hide();
		}
		
	}
	
	return {
		init: init
	}
}();

$(document).ready(function(){
	MHLandscaping.init();
});